import java.io.*;


//所有行数据
public class allLineTest {
    public static void main(String[] args) throws Exception {

        File file = new File("C:\\Users\\Administrator\\Desktop\\ccccc\\22_03_31Receive.txt");/*文件名*/


        String aa = txt2String(file);

//      String[] strings =aa.split("\u001C");
        String[] strings = aa.split("\u001C");

        int line = getTotalLines("C:\\Users\\Administrator\\Desktop\\ccccc\\22_03_31Receive.txt");
        System.out.println(line);

//       System.out.println(aa);
        System.out.println(strings);
        System.out.println(strings.length);

    }

    /**
     * 读取txt文件的内容
     *
     * @param file 想要读取的文件对象
     * @return 返回文件内容
     */

    public static String txt2String(File file) {

        StringBuilder result = new StringBuilder();

        try {
            //构造一个BufferedReader类来读取文件
            BufferedReader br = new BufferedReader(new FileReader(file));

            String s = null;
            //使用readLine方法，一次读一行
            while ((s = br.readLine()) != null) {
                result.append(System.lineSeparator() + s);
            }
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.toString();
    }

    // 文件内容的总行数
    static int getTotalLines(String fileName) throws IOException {
        //使用缓冲区的方法将数据读入到缓冲区中
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
        LineNumberReader reader = new LineNumberReader(br);
        //定义行数
        String s = reader.readLine();
        int lines = 0;
        //确定行数
        while (s != null) {
            lines++;
            s = reader.readLine();
        }
        reader.close();
        br.close();
        //返回行数
        return lines;
    }






}
